# -*- coding:utf8 -*-

from Allele import Allele

class Gene:
    """Class Gene
    """
    # Attributes:
    __ListeAllele = None  # (List <Allele>) 
    __Nom = None  # (String) 
    __alleleDefaut = None  # (<Allele>)
    __id = 0
    
    # Operations
    def __init__(self, in_nom):
        """function Gene
        
        in_nom: String
        
        returns 
        """
        self.__ListeAllele = {}
        self.__Nom = in_nom

    def setId(self, id):
        """function setId
        
        returns
        """
        self.__id = id

    def getId(self):
        """function getId
        
        returns int
        """
        return self.__id

    def ajouterAllele(self, in_Allele):
        """function ajouterAllele
        
        in_Allele: <Allele>
        
        returns boolean
        """

        if(isinstance(in_Allele, Allele)):
            in_Allele.setId(len(self.__ListeAllele))
            self.__ListeAllele[in_Allele.getId()] = in_Allele
            return True
        else:
            return False
    
    def identifier(self):
        """function identifier
        
        returns <Allele>
        """
        return None
    
    def getName(self):
        """function getNom
        
        returns String
        """
        return self.__Nom
    
    def getAlleles(self):
        """function getAlleles
        
        returns List <Allele>
        """
        return self.__ListeAllele

    def getAllelesName(self):
        """function getAllelesName
        
        returns string
        """
        names = []
        for a in self.__ListeAllele.values():
            names.append(a.getName())
        return names

    def getAlleleByName(self, name):
        for allele in self.__ListeAllele.values():
            if allele.getName() == name:
                return allele
        return None

    def getAlleleById(self, in_id):
        if self.__ListeAllele.has_key(in_id):
            return self.__ListeAllele[in_id]
        return None
    
    def setDefautAllele(self, in_allele):
        """function setDefautAllele
        
        in_allele: <Allele>
        
        returns 
        """
        if(isinstance(in_allele, Allele)):
            # @type in_allele Allele
            if(not self.__ListeAllele.has_key(in_allele.getValeur())):
                self.ajouterAllele(in_allele)
            self.__alleleDefaut = in_allele
            return True
        else:
            return False

    def getDefaultAllele(self):
        """Documentation"""
        return self.__alleleDefaut
    
#    def __str__(self):
#        if(self.__alleleDefaut != None):
#            retour = self.__Nom + " : " + str(self.__alleleDefaut)
#        else:
#            retour = self.__Nom
#        return retour
